* Gary LaMotte's Mathematica solutions to exercises from the 2012 Gravitational Wave Astronomy Summer School

*DAY 1

1.MATLAB WARM-UPS*

samprate = 16384;

nsec=1.0;

ndata=nsec*samprate;

time = Table[(r-1.0)/ndata  , {r,ndata}];

twosines = 5*Sin[2*Pi*74.7*time] + 2*Sin[2*Pi*820*time];

noise = Table[RandomVariate[NormalDistribution[0,1.4],ndata]];

nt = noise + twosines;

timeseries = Transpose[{time, nt}];

ListLinePlot[timeseries, PlotLabel -> Timeseries, AxesLabel ->  {Time (Secs), Amplitude}]

ListLinePlot[timeseries, PlotLabel -> Timeseries, AxesLabel ->  {Time (Secs), Amplitude}, PlotRange-> {{0,0.05}, {-11,11}}]

Mean[nt]

StandardDeviation[nt ]

*2. FOURIER DOMAIN REPRESENTATION*

ftnt = Fourier[nt];

ListLinePlot[Abs[(ftnt)^2] ,PlotRange -> {{0,16384},{0, 80000}}]

ListLogPlot[Abs[(ftnt)^2],PlotRange->{{0,16384},{5,300000}},Joined->True, PlotLabel-> Periodogram, AxesLabel-> {Frequency, Amp^2}]
*Very tedious and long to develop this input.  Seems it should have been much more simple.*

ListLogPlot[Abs[(ftnt)^2] ,PlotRange -> {{0,1000},{2, 300000}},Joined->True, PlotLabel-> Periodogram, AxesLabel-> {Frequency, Amp^2}]

*Note spectral leakage around 74.7Hz but not around 820Hz (because 820Hz is an exactly represented frequency and 16.7Hz is not).*

*Parseval's Theorem*

timedomainenergy= nt^2;

Total[timedomainenergy]

*Now for frequency domain energy*

frequencydomainenergy = Abs[(ftnt)^2];

Total[frequencydomainenergy]

*These are identical confirming Parseval's  Theorem*

*Hann Window*

postHann = (nt) * (1-Cos[2*Pi*time])/2;

postHannseries = Transpose[{time, postHann}];

ListLinePlot[postHannseries, PlotLabel -> Timeseries, AxesLabel ->  {Time (Secs), Amplitude}]

ftpostHann = Fourier[postHann];

ListLogPlot[Abs[(ftpostHann)^2],PlotRange->{{0,16384},{0.5,50000}},Joined->True, PlotLabel-> Periodogram, AxesLabel-> {Frequency, Amp^2}]
*Very tedious and long to develop this input.  Seems it should have been much more simple.*

ListLogPlot[Abs[(ftpostHann)^2] ,PlotRange -> {{0,1000},{0.5, 50000}},Joined->True, PlotLabel-> Periodogram, AxesLabel-> {Frequency, Amp^2}]

*Note spectral leakage around 74.7Hz has largely resolved because of filtering by the Hann window*